let a = [1, 2, 3, 4, 5, 5]
let b = [3, 4, 5, 6, 7, 7]

// 去重
function removeDuplicates (data) {
    return [...new Set(data)] // 或 Array.from(new Set(data))
}

// 1.交集
function intersection (a, b) {
    return removeDuplicates(a.filter(v => b.includes(v)))
}

console.log(intersection(a, b)) // [ 3, 4, 5 ]

// 2.并集
function union (a, b) {
    return removeDuplicates([...a, ...b])
}

console.log(union(a, b)) // [  1, 2, 3, 4, 5, 6, 7]

// 3.差集
function difference (a, b) {
    return removeDuplicates(a.filter(v => !b.includes(v)))
}

console.log(difference(a, b))    // [ 1, 2 ]
console.log(difference(b, a))    // [ 6, 7 ]

// 4.对称差集
function exclusiveOr (a, b) {
    return removeDuplicates(a.concat(b).filter(v => !a.includes(v) || !b.includes(v)))
}

console.log(exclusiveOr(a, b)) // [ 1, 2, 6, 7 ]

